home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / TTERM.C < prev    next >
C/C++ Source or Header  |  1991-10-29  |  5KB  |  147 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/users/jinx/microcode/RCS/tterm.c,v 1.2 1991/10/29 22:55:11 jinx Exp $
  4.  
  5. Copyright (c) 1990-1991 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* termcap(3) interface for Scheme. */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39. #include "osterm.h"
  40.  
  41. extern int EXFUN (tgetent, (char *, char *));
  42. extern int EXFUN (tgetnum, (char *));
  43. extern int EXFUN (tgetflag, (char *));
  44. extern char * EXFUN (tgetstr, (char *, char **));
  45. extern char * EXFUN (tparam, (char *, char*, int, int, ...));
  46. extern char * EXFUN (tgoto, (char *, int, int));
  47. extern int EXFUN (tputs, (char *, int, void (*) (int)));
  48. extern char * BC;
  49. extern char * UP;
  50. extern char PC;
  51. extern short ospeed;
  52.  
  53. #ifndef TERMCAP_BUFFER_SIZE
  54. #define TERMCAP_BUFFER_SIZE 2048
  55. #endif
  56.  
  57. static char termcap_buffer [TERMCAP_BUFFER_SIZE];
  58. static char tgetstr_buffer [TERMCAP_BUFFER_SIZE];
  59. static char * tgetstr_pointer;
  60.  
  61. static char tputs_output [TERMCAP_BUFFER_SIZE];
  62. static char * tputs_output_scan;
  63.  
  64. static void
  65. DEFUN (tputs_write_char, (c), int c)
  66. {
  67.   (*tputs_output_scan++) = c;
  68.   return;
  69. }
  70.  
  71. DEFINE_PRIMITIVE ("TERMCAP-INITIALIZE", Prim_termcap_initialize, 1, 1, 0)
  72. {
  73.   PRIMITIVE_HEADER (1);
  74.   tgetstr_pointer = tgetstr_buffer;
  75.   PRIMITIVE_RETURN
  76.     (BOOLEAN_TO_OBJECT ((tgetent (termcap_buffer, (STRING_ARG (1)))) > 0));
  77. }
  78.  
  79. DEFINE_PRIMITIVE ("TERMCAP-GET-NUMBER", Prim_termcap_get_number, 1, 1, 0)
  80. {
  81.   PRIMITIVE_HEADER (1);
  82.   {
  83.     int result = (tgetnum (STRING_ARG (1)));
  84.     PRIMITIVE_RETURN ((result < 0) ? SHARP_F : (long_to_integer (result)));
  85.   }
  86. }
  87.  
  88. DEFINE_PRIMITIVE ("TERMCAP-GET-FLAG", Prim_termcap_get_flag, 1, 1, 0)
  89. {
  90.   PRIMITIVE_HEADER (1);
  91.   PRIMITIVE_RETURN (BOOLEAN_TO_OBJECT ((tgetflag (STRING_ARG (1))) != 0));
  92. }
  93.  
  94. DEFINE_PRIMITIVE ("TERMCAP-GET-STRING", Prim_termcap_get_string, 1, 1, 0)
  95. {
  96.   PRIMITIVE_HEADER (1);
  97.   {
  98.     char * result = (tgetstr ((STRING_ARG (1)), (&tgetstr_pointer)));
  99.     PRIMITIVE_RETURN
  100.       ((result == 0) ? SHARP_F
  101.        : (char_pointer_to_string ((unsigned char *) result)));
  102.   }
  103. }
  104.  
  105. DEFINE_PRIMITIVE ("TERMCAP-PARAM-STRING", Prim_termcap_param_string, 5, 5, 0)
  106. {
  107.   PRIMITIVE_HEADER (5);
  108.   {
  109.     char * s =
  110.       (tparam ((STRING_ARG (1)), 0, 0,
  111.            (arg_nonnegative_integer (2)),
  112.            (arg_nonnegative_integer (3)),
  113.            (arg_nonnegative_integer (4)),
  114.            (arg_nonnegative_integer (5))));
  115.     SCHEME_OBJECT result = (char_pointer_to_string ((unsigned char *) s));
  116.     free (s);
  117.     PRIMITIVE_RETURN (result);
  118.   }
  119. }
  120.  
  121. DEFINE_PRIMITIVE ("TERMCAP-GOTO-STRING", Prim_termcap_goto_string, 5, 5, 0)
  122. {
  123.   PRIMITIVE_HEADER (5);
  124.   {
  125.     BC = (((ARG_REF (4)) == SHARP_F) ? 0 : (STRING_ARG (4)));
  126.     UP = (((ARG_REF (5)) == SHARP_F) ? 0 : (STRING_ARG (5)));
  127.     PRIMITIVE_RETURN
  128.       (char_pointer_to_string
  129.        ((unsigned char *)
  130.     (tgoto ((STRING_ARG (1)),
  131.         (arg_nonnegative_integer (2)),
  132.         (arg_nonnegative_integer (3))))));
  133.   }
  134. }
  135.  
  136. DEFINE_PRIMITIVE ("TERMCAP-PAD-STRING", Prim_termcap_pad_string, 4, 4, 0)
  137. {
  138.   PRIMITIVE_HEADER (4);
  139.   ospeed = (arg_baud_index (3));
  140.   PC = (((ARG_REF (4)) == SHARP_F) ? '\0' : ((STRING_ARG (4)) [0]));
  141.   tputs_output_scan = tputs_output;
  142.   tputs ((STRING_ARG (1)), (arg_nonnegative_integer (2)), tputs_write_char);
  143.   PRIMITIVE_RETURN
  144.     (memory_to_string ((tputs_output_scan - tputs_output),
  145.                ((unsigned char *) tputs_output)));
  146. }
  147.